package cn.enilu.guns.admin.core.util;

import cn.enilu.guns.admin.common.constant.device.ColumnConstant;
import cn.enilu.guns.bean.entity.door.EventRecord;
import cn.enilu.guns.bean.entity.system.User;
import cn.enilu.guns.utils.StringUtils;
import com.jwz.app.DateUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 向门禁设备中设置数据转换工具类
 *
 * @author fengshuonan
 * @date 2016年12月6日 下午1:01:54
 */
public class EntranceDataUtil {

    /**
     * @Description 向门禁设备中设置数据转换
     * @author fengshuonan
     */
    public static String parse(List<?> list) {
        String str = "";
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                str = str + list.get(i).toString();
                if(i != list.size() - 1){
                    str = str + "\r\n";
                }
            }
        }
        return str;
    }

    /**
     * 转换从设备中读取的数据
     * @param deviceData
     * @return
     */
    public static Map<String,String> parseData(String deviceData){
        Map<String, String> rsMap = new HashMap<String, String>();
        String[] deviceDatas = deviceData.split("\t");
        for (String data:deviceDatas) {
            rsMap.put(data.split("=")[0],data.split("=")[1]);
        }
        return rsMap;
    }

    /**
     * 转换从设备中读取的參數数据
     * @param deviceData
     * @return
     */
    public static Map<String,String> parseParams(String deviceData){
        Map<String, String> rsMap = new HashMap<String, String>();
        String[] deviceDatas = deviceData.split(",");
        for (String data:deviceDatas) {
            rsMap.put(data.split("=")[0],data.split("=")[1]);
        }
        return rsMap;
    }
    public static void main(String[] args) {
//        ArrayList<User> arrayList = new ArrayList<>();
//        for (int i = 0; i < 10; i++) {
//            User user = new User();
//            user.setCredentialsNo("123456789");
//            user.setName("zhangsan");
//            arrayList.add(user);
//        }
//        System.out.println(parse(arrayList));
//        String transactionData = "Pin=1\tVerified=ver\tDoorID=121\t" +"\r\n"+
//                "Pin=2\tVerified=ver2\tDoorID=122\t" +"\r\n"+
//                "Pin=3\tVerified=ver3\tDoorID=123\t" +"\r\n"+
//                "Pin=4\tVerified=ver4\tDoorID=124\t" +"\r\n"+
//                "Pin=5\tVerified=ver5\tDoorID=125\t" +"\r\n"+
//                "Pin=6\tVerified=ver6\tDoorID=126\t" +"\r\n";
//
//        String[] records = transactionData.split("\r\n");
//        for (String record:records) {
//            Map<String,String> map = EntranceDataUtil.parseData(record);
//            EventRecord eventRecord = new EventRecord();
//            eventRecord.setPin(Long.parseLong(map.get(ColumnConstant.TRANSACTION_PIN)));
//            eventRecord.setVerified(map.get(ColumnConstant.TRANSACTION_VERIFIED));
//            eventRecord.setDoorId(Integer.valueOf(map.get(ColumnConstant.TRANSACTION_DOORID)));
//            eventRecord.setEventType(map.get(ColumnConstant.TRANSACTION_EVENTTYPE));
//            eventRecord.setInoutState(map.get(ColumnConstant.TRANSACTION_INOUTSTATE));
//            eventRecord.setTimeSecond(DateUtils.convertStr2Date(map.get(ColumnConstant.TRANSACTION_TIME_SECOND)));
//            eventRecord.setInoutfunIndex(Integer.valueOf(map.get(ColumnConstant.TRANSACTION_INDEX)));
//            eventRecord.setCardNo(Long.parseLong(map.get(ColumnConstant.TRANSACTION_CARDNO)));
//            eventRecord.setSiteCode(Integer.valueOf(map.get(ColumnConstant.TRANSACTION_SITECODE)));
//            System.out.println(eventRecord);
//        }
    }
}
